<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <title>猜数字游戏</title>
   </head>
   <body>
      <script>
         function getRandom(min, max){
            return Math.floor(Math.random() * (max - min +1) + min)
         }
         let random = getRandom(1, 10)
         let flag = true
         let count = 3
    /*     for (let i = 1; i < 3; i++) {
            if(guess > random){
               alert('您猜大了!')
               alert(`您还有${count - i}次机会`)
            }else if (guess < random){
               alert('您猜小了!')
               alert(`您还有${count - i}次机会`)
            }else{
               flag = false
               alert('恭喜你猜对了!')
               break
            }
         }
         */
         while(flag && count > 0){
            guess = +prompt('请输入你猜的数字(1~10)')
            if(guess > random){
               alert('您猜大了!')
               alert(`您还有${count - 1}次机会`)
               count--
            }else if (guess < random){
               alert('您猜小了!')
               alert(`您还有${count - 1}次机会`)
               count--
            }else{
               flag = false
               alert('恭喜你猜对了!')
               break
            }
         }
         if(flag){
            alert('您的次数已用完,Game Over!')
         }


      </script>
   </body>
</html>